<script src="../js/axios.js"></script>
<meta charset="UTF-8">
<script>
  /**
   * 比较两个对象，如果对象的属性值都相等，则返回true，否则返回false,没有对象属性
   * @param obj1
   * @param obj2
   */
  function compareObject(obj1, obj2) {
    if (!obj1) {
      return false
    }
    if (!obj2) {
      return false
    }
    let keys1 = Object.keys(obj1)
    if (keys1.length === 0) {
      return false
    }
    let keys2 = Object.keys(obj2)
    if (keys2.length === 0) {
      return false
    }
    if (keys2.length !== keys1.length) {
      return false
    }
    //属性名称不相等
    for (let i = 0; i < keys1.length; i++) {
      if (keys1[i] !== keys2[i]) {
        return false
      }
    }
    let values1 = Object.values(obj1)
    let values2 = Object.values(obj2)
    for (let i = 0; i < values1.length; i++) {
      console.log(typeof values1[i])
      if (typeof values1[i] === 'object') {
        return compareObject(values1[i], values2[i])
      } else {
        if (values1[i] !== values2[i]) {
          return false
        }
      }
    }
    return true
  }

  console.log(compareObject({ name: { nickName: 'tom' }, age: 20 }, { name: { nickName: 'tom' }, age: 20 }))
</script>
